<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>编辑HTTP信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="./layui/css/layui.css" th:href="@{/layui/css/layui.css}" media="all">
    <link rel="stylesheet" href="./style/myself.css" th:href="@{/style/myself.css}" media="all">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="./js/html5.min.js" th:src="@{/js/html5.min.js}"></script>
    <script src="./js/respond.min.js" th:src="@{/js/respond.min.js}"></script>
    <![endif]-->
    <script type="text/javascript" charset="utf-8" th:inline="javascript">
        var ctxPath = /*[[@{/}]]*/'';
    </script>
</head>
<body>
<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin"
     style="padding: 20px 20px 0 0;">
    <div class="layui-form-item" style="display: none;">
        <label class="layui-form-label">HTTP ID</label>
        <div class="layui-input-block">
            <input type="hidden" name="id" autocomplete="off" readonly
                   class="layui-input" th:value="${monitorHttpVo.id}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">目标URL</label>
        <div class="layui-input-block">
            <input type="text" name="urlTarget" lay-verify="url" autocomplete="off"
                   class="layui-input" lay-verType="tips" th:value="${monitorHttpVo.urlTarget}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">请求方法</label>
        <div class="layui-input-block" id="method-radio">
            <input type="radio" name="method" lay-filter="method" value="GET" title="GET"
                   th:checked="${monitorHttpVo.method=='GET'}? true : false">
            <input type="radio" name="method" lay-filter="method" value="POST" title="POST"
                   th:checked="${monitorHttpVo.method=='POST'}? true : false">
        </div>
    </div>
    <div class="layui-form-item" id="parameter-item" style="display: none;">
        <label class="layui-form-label">POST入参(可以为空)</label>
        <div class="layui-input-block">
            <textarea name="parameter" th:text="${monitorHttpVo.parameter}" class="layui-textarea" autocomplete="off"
                      style="height: 200px;" placeholder='{
    "hostname":"192.168.1.8",
    "page":1,
    "pageSize":10
}'></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">环境</label>
        <div class="layui-input-block">
            <select name="monitorEnv">
                <option value="">不设置</option>
                <option th:each="monitorEnv:${monitorEnvs}" th:value="${monitorEnv}"
                        th:text="${monitorEnv}" th:selected="${monitorEnv==env}"></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分组</label>
        <div class="layui-input-block">
            <select name="monitorGroup">
                <option value="">不设置</option>
                <option th:each="monitorGroup:${monitorGroups}" th:value="${monitorGroup}"
                        th:text="${monitorGroup}" th:selected="${monitorGroup==group}"></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea name="descr" class="layui-textarea" th:text="${monitorHttpVo.descr}"
                      placeholder="请输入描述" autocomplete="off"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-front-submit" id="LAY-front-submit" value="确认">
    </div>
</div>
<script src="./layui/layui.js" th:src="@{/layui/layui.js}"></script>
<script>
    layui.config({
        base: ctxPath //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'jquery'], function () {
        var form = layui.form, $ = layui.$;
        // 监听请求方法选择
        form.on('radio(method)', function (data) {
            var method = data.value;
            if (method === 'POST') {
                $('#parameter-item').show();
            } else {
                $('#parameter-item').hide();
            }
        });
        // 打开页面如果选择的是POST，显示此div
        if ($("input[name='method']:checked").val() === 'POST') {
            $('#parameter-item').show();
        }

        // 校验IP地址合法性
        form.verify({
            //ip: function (value) {
            //    var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
            //    if (!reg.test(value)) {
            //        return '请输入合法IP';
            //    }
            //},
            //port: function (value) {
            //    var reg = /^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/;
            //    if (!reg.test(value)) {
            //        return '请输入合法端口';
            //    }
            //}
        });
    });
</script>
</body>
</html>